﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace XPathAutoSuggest.ViewModels {
    /// <summary>
    /// ModelView suitable for controlling a view which displays links to help pages on the web
    /// </summary>
    public class HelpLinks_ViewModel : IHelpLinksVM, IXPathToolVm
    {
        private GoLinksCommand _GoLinksCommand;
        private CloseLinksCommand _CloseLinksCommand;

        /// <summary>
        /// Method signature for the event we will raise when user wants to close the form
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public delegate void CloseCommandDlgt(object sender, EventArgs e);
        
        /// <summary>Event we fire when user wants to close the form</summary>
        public event CloseCommandDlgt CloseLinks;

        /// <summary>
        /// Default constructor builds a couple commands to expose
        /// </summary>
        public HelpLinks_ViewModel() {
            _GoLinksCommand = new GoLinksCommand(this);
            _CloseLinksCommand = new CloseLinksCommand(this);
        }

        /// <summary>
        /// Publicly exposes our command for binding
        /// </summary>
        public GoLinksCommand GoLinksCommand {
            get { return _GoLinksCommand; }
        }

        /// <summary>
        /// Publicly exposes our command for binding
        /// </summary>
        public CloseLinksCommand CloseLinksCommand {
            get { return _CloseLinksCommand; }
        }

        /// <summary>
        /// user can always execute the go links command
        /// </summary>
        /// <returns></returns>
        public bool GoLinksCommandCanExecute() {
            return true;
        }

        /// <summary>
        /// Fires when user clicks a link, loads users browser using the specified address
        /// </summary>
        /// <param name="uri"></param>
        public void GoLinksCommandExecute(string uri) {
            System.Diagnostics.Process.Start(uri);
        }

        /// <summary>
        /// User can always execute the close command
        /// </summary>
        /// <returns>true</returns>
        public bool CloseLinksCommandCanExecute() {
            return true;
        }

        /// <summary>
        /// Fired when user wants to close the form
        /// </summary>
        public void CloseLinksCommandExecute() {
            if (CloseLinks != null) {
                CloseLinks(this, new EventArgs());
            }
        }
    }
}
